package org.matrix.base
{

	public class Matrix4D extends Matrix3D
	{
		public function Matrix4D(depth:uint){super(depth);	d4Lenght = d3Lenght * depth;}
		
		override public function get dimensions():uint		{return 4}
		
		internal var d4Lenght:uint;
		protected var d4Index:uint;
		internal var d4Dirty:Boolean;
		internal var d4:Vector.<Vector.<Vector.<Vector.<Number>>>>;
		override protected function init():void
		{
			d4 = new Vector.<Vector.<Vector.<Vector.<Number>>>>(depth,true);
			for (var i:uint; i < depth; i++)
			{
				super.init();
				d4[i] = d3;
			}
		}
		
		override public function getElement( ... keys:Array):Number				{return d4[keys.unshift()][keys.unshift()][keys.unshift()][keys.unshift()]}
		override public function setElement(value:Number, ... keys:Array):void	{d4[keys.unshift()][keys.unshift()][keys.unshift()][keys.unshift()] = value}
		
		override public function get index():uint	{return d4Index * d3Lenght + super.index}
		
		override protected function validate():void
		{
			if (d3Dirty)
			{
				d3 = d4[d4Index];
				d3Dirty = false;
				d2Dirty = true;
			}
			return super.validate();
		}
		
		protected function d5Inc(recursive:Boolean = false):void
		{
			if (recursive)
				d4Index = 0;
			else
				throw new Error('')
		}
		final override protected function d4Inc(recursive:Boolean = false):void
		{
			if (++ d4Index == depth)
				d5Inc(d4Dirty = true);
			if (recursive)
				d3Index = 0;
		}


	}
}